//
//  PHScrollViewController.m
//  mmmmmm
//
//  Created by weiduowang on 14-12-14.
//  Copyright (c) 2014年 weiduowang. All rights reserved.
//

#import "PHScrollViewController.h"
#import "Unit.h"
@interface PHScrollViewController ()

@end

@implementation PHScrollViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    [self.view addSubview:image];
    
    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, screen_Width, screen_Height)];
    scrollView.showsHorizontalScrollIndicator=NO;
    scrollView.pagingEnabled = YES;
    scrollView.delegate = self;
    scrollView.contentSize=CGSizeMake(320*2, screen_Height);
    [self.view addSubview:scrollView];
    
   
    
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(10, 20, 44, 44);
    
    //    button.backgroundColor = [UIColor colorWithPatternImage:];
    [button setImage:[UIImage imageNamed:@"天使详情页-返回键-"] forState: UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    
    
    

    
    
    
    
    //位置1   0 0
    UIImageView *image1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, screen_Height)];
    [image1 setImage:[UIImage imageNamed:@"天使详情页-背景-"]];
    [scrollView addSubview:image1];
    
    
    
    //位置3   640  0
    UIImageView *image2=[[UIImageView alloc]initWithFrame:CGRectMake(320, 0, 320, screen_Height)];
    [image2 setImage:[UIImage imageNamed:@"天使详情页-背景2-"]];
    [scrollView addSubview:image2];
    
    
    

    
    //位置2   320  0
    UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(320, 0, 320, screen_Height)];
    UIImageView *img1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, screen_Height)];
    [img1 setImage:[UIImage imageNamed:@"专家天使-显示文字-"]];
    [view1 addSubview:img1];
    view1.tag = 10000;
    
    [scrollView addSubview:view1];
    
    //位置4   960  0
    UIView *view2=[[UIView alloc]initWithFrame:CGRectMake(640, 0, 320, screen_Height)];
    UIImageView *img2=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, screen_Height)];
    [img2 setImage:[UIImage imageNamed:@"专家天使-显示文字2-"]];
    [view2 addSubview:img2];
    view2.tag = 10001;
    [scrollView addSubview:view2];
    
    
    
    
    
    
    
    
    
    

    
    
    
    UIButton *button2=[UIButton buttonWithType:UIButtonTypeCustom];
    button2.frame=CGRectMake(320/2-25, screen_Height-44, 50, 44);
    button2.tag=2;
    [button2 addTarget:self action:@selector(tapbutton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button2];
    
    

    
    
    
    
    
    
    
    
    
    
    // Do any additional setup after loading the view.
}

- (void)backHome {
    
    UIView *view = [self.view viewWithTag:1000];
    
    [UIView animateWithDuration:KLongDuration animations:^{
        view.frame = CGRectMake(0, screen_Height, screen_Width, screen_Height);
    } completion:^(BOOL finished) {
        if (finished ) {
            [view removeFromSuperview];
        }
    }];
    
    
 
}

-(void)tapbutton:(UIButton *)button
{
    
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, screen_Height, screen_Width, screen_Height)];
    [self.view  addSubview:view];
    view.tag = 1000;

    view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"上图-"]];
    
    
    UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
    b.frame = CGRectMake(0, 0, 320, 150);
    [b addTarget:self action:@selector(backHome) forControlEvents:UIControlEventTouchUpInside];
    
    [view addSubview:b];
    
    
    
    [UIView animateWithDuration:KMiddleDuration animations:^{
        view.frame = self.view.frame;
    }];
    

    
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    
    [self viewLoad:0];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)viewLoad:(int)index {

    if ( index == 0 ) {
        
        UIView *v = [self.view viewWithTag:10000];
        UIView *v1 = [self.view viewWithTag:10001];

        [UIView animateWithDuration:KLongDuration animations:^{

            v.frame = CGRectMake(0, 0, 320, screen_Height);
            v.alpha = 1;

        }];
        v1.alpha = 0;
        v1.frame = CGRectMake(640, 0, 320, screen_Height);
    }
    else if (index == 1) {
        
        UIView *v = [self.view viewWithTag:10000];
        UIView *v1 = [self.view viewWithTag:10001];
        
        [UIView animateWithDuration:KLongDuration animations:^{
            
            v1.frame = CGRectMake(320, 0, 320, screen_Height);
            v1.alpha = 1;
            
        }];
        v.alpha = 0;
        v.frame = CGRectMake(320, 0, 320, screen_Height);
    }
    

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
 
    int index = (int)(scrollView.contentOffset.x / scrollView.frame.size.width);

    
        [self viewLoad:index];


}
@end
